/*
 * Copyright 2007 Soluvas.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ops4j.pax.script.internal;

import java.util.Dictionary;
import java.util.Hashtable;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;

/**
 * Pax-Script is an extender that automatically registers JSR223 engines (javax.script.ScriptEngineFactory) as OSGi
 * services when a JSR223 JAR is loaded.
 * 
 * SCM: http://scm.ops4j.org/browse/OPS4J/laboratory/users/ceefour/pax-script
 * 
 * Also "jointly developed" with JSR223: https://scripting.dev.java.net/issues/show_bug.cgi?id=34
 * 
 * An effort is undergoing to make all JSR223 engines OSGi-compliant. Right now Groovy engine is directly usable by
 * Pax-Script.
 * 
 * Highly inspired by Apache Sling's SlingScriptAdapterFactory:
 * 
 * http://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/
 * impl/SlingScriptAdapterFactory.java
 */
public final class ScriptEngineFactoryConverter extends JavaServiceToOsgiServiceConverter<ScriptEngineFactory> {
    public ScriptEngineFactoryConverter() {
        super(ScriptEngineFactory.class);
    }

    @Override
    protected Dictionary<String, Object> createProperties(ScriptEngineFactory factory) {
        Dictionary<String, Object> properties = new Hashtable<String, Object>();
        properties.put("name", (String) factory.getParameter(ScriptEngine.NAME));
        properties.put("engine.name", factory.getEngineName());
        properties.put("engine.version", factory.getEngineVersion());
        properties.put("language", factory.getLanguageName()); // legacy/convenience
        properties.put("language.name", factory.getLanguageName());
        properties.put("language.version", factory.getLanguageVersion());

        return properties;
    }
}